<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>证书产品配置</title>
    <c:import url="../../header.jsp"/>
    <link rel="stylesheet" href="${rootUrl}/static/css/time-status-color.css?v=${version}">
    <script> var ALLOT_REFUSED = '${ALLOT_REFUSED}';</script>
    <style>
        table.crm-table.cell-border tbody td{
            white-space: nowrap;
        }
    </style>
</head>
<body>
<div class="body-main" >
      <div class="table-conter">
          <br>
          <a href="javascript:void(0)" class="layui-btn layui-btn-mini" onclick="OpenCreate()">新增</a>
    </div>
    <br>
    <div class="table-body">
        <!--表格 start-->
        <table id="myProductTable" class="cell-border crm-table columnsHidden dataTable">
            <thead>
            <tr>
                <th>一级业态</th>
                <th>二级业态</th>
                <th>产品名称</th>
                <th>产品编号</th>
                <th>最后操作人</th>
                <th>最后操作时间</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
        </table>
        <!--表格 end-->
    </div>
</div>
<c:import url="/WEB-INF/jsp/footer.jsp"/>
<script type="text/javascript" charset="utf-8">
    var NORMAL = '${NORMAL}', TIME_OUT = '${TIME_OUT}';
</script>
<script type="text/javascript" src="${basePath}/static/js/zzsc/production/sc_common.js?v=${version}"></script>
<script type="text/javascript">

    // 获取搜索数据
    function getSearchData() {
        return $.extend($('.main-title').serializeJson(), $('.titleSearch').serializeJson());
    }

    $(document).ready(function () {
		//初始化dataTable列表
        table = $('#myProductTable').dataTableExtend({
            "ajax": {"url": "${basePath}/zz/zspz/select.do", "type": "post"},
            "fnServerParams": function (aoData) {
                aoData = $.extend(aoData, getSearchData());
                return aoData;
            },

            "pageLength": 10,//每页显示的条数默认是10条，有特殊业务需要显示不同条数的列表才应该加入该参数
            "scrollX": "true",//是否开启横项滚动
            "fixedColumns": {//锁定列，只有开启scrollX时才生效
                "leftColumns": 4,//左侧锁定2列
                "rightColumns": 1//右侧锁定1列
            },
            "aoColumns": [
                {
                    "orderable": false,
                    "data": "primaryBusinessName",
                }, {
                    "orderable": false,
                    "data": "secondBusinessName",

                }, {
                    "orderable": false,
                    "data": "productName",

                }
                ,{
                    "orderable": false,
                    "data": "productNo",
                },
                {
                    "orderable": false,
                    "data": "lastOperatorName",
                },
                {
                    "orderable": false,
                    "data": "lastOperationTime",

                },
                {
                    "orderable": false,
                    "data": "operation",
                    "render": function (data, type, full, meta) {
                        if(data == 0){
                            return '启用';
                        }else{
                            return '禁用';
                        }
                    }
                },
                {
                    "orderable": false,
                    "data": "id",
                    "width": "190",
                    "render": function (data, type, r, meta) {
                        var name = "禁用"
                        if(r.operation== 1){
                            name =  '启用';
                        }
                        var result = "";
                        result += '<a href=\'javascript:void(0)\' class="layui-table-link"  onclick="editMatching(\'' + r.id + '\',\'' + r.operation + '\')" /><span style="color: #0066ff ">' + name + '</a>&nbsp;&nbsp;';
                        result += '<a href=\'javascript:void(0)\' class="layui-table-link"  onclick="deleteMatching(\'' + r.id + '\')" /><span style="color: #0066ff ">删除</a>';
                        return result;
                    }
                }],
        });
    });
    /**
     *调证书产品新增页面
     */
    function OpenCreate(){
        DGG.loading();
        $.post(sysInfo.basePath + "/zs/talent/add_production_configuration.html", function (data) {
            dgg.Open({
                title: '新增证书产品',
                content: data,
                area: ['500px','300px'],
                btn: ["确定", "取消"],
                yes: function () {
                    addCertificateProduct();
                }, btn2: function () {
                    DGG.loading('close');
                }
            });
        }, 'html');
    }
    function addCertificateProduct(){
        var primaryBusinessForms = $('[name="primaryBusinessForms"]').val();
        var secondBusinessId = $('[name="secondBusinessId"]').val();
        var productId = $('[name="productId"]').val();
        var productId1  = $("#productId").find('option:selected').text();
        // var productNo = $('[name="productNo"]').val();
        var lastOperatorName = $('[name="lastOperatorName"]').val();
        var lastOperationTime = $('[name="lastOperationTime"]').val();
        var productNo = $("#business_typeCode1").val();
        // var secondBusinessForms =$("#business_typeCode1").find('option:selected').text();

        if(isEmpty(secondBusinessId)){
            DGG.Warning('请选择二级业态！');
            return;
        }
        if(isEmpty((productId))){
            DGG.Warning('请选择产品名称!');
            return;
        }
        // if(isEmpty((productNo))){
        //     DGG.Warning('产品编号不能为空！');
        //     return;
        // }
        // if(!isEmpty((lastOperatorName))){
        //     DGG.Warning('操作人不能为空！');
        //     return;
        // }



        var params=$('#flowLongCreate').serializeArray();

        DGG.Confire("确定新增证书产品？", '新增证书产品', function () {
            DGG.loading();
            $.ajax({
                type: 'POST',
                async: true,
                data: params,
                url: sysInfo.basePath + '/zz/zspz/save.do',
                dataType: 'JSON',
                success: function (data) {
                    DGG.loading('close');
                    if (data.code == 0) {
                        DGG.Succeed('操作成功！')
                        setTimeout(function () {
                            layer.closeAll();
                        }, 1000);
                        reloadTable2();
                    } else {
                        DGG.Errors(data.msg);
                    }
                },
                error: function () {
                    DGG.Errors('保存失败，请联系管理员！！');
                }
            })
        }, function () {
        })
    }

    function reloadTable2() {
        $('#myProductTable').dataTableExtend("reload");
    }
    function editMatching(id,operation) {
        DGG.Confire("确定修改状态？", '修改证书状态', function () {
            DGG.loading();
            $.ajax({
                type: 'POST',
                async: true,
                data: {"id": id,"operation":operation},
                url: sysInfo.basePath + '/zz/zspz/edit.do',
                dataType: 'JSON',
                success: function (data) {
                    DGG.loading('close');
                    if (data.code == 0) {
                        DGG.Succeed('操作成功！')
                        setTimeout(function () {
                            layer.closeAll();
                        }, 1000);
                        reloadTable2();
                    } else {
                        DGG.Errors(data.msg);
                    }
                },
                error: function () {
                    DGG.Errors('删除失败，请联系管理员！！');
                }
            })
        }, function () {
        })
    }
    function deleteMatching(id) {
        DGG.Confire("确定删除配置？", '删除证书配置', function () {
            DGG.loading();
            $.ajax({
                type: 'POST',
                async: true,
                data: {"id": id},
                url: sysInfo.basePath + '/zz/zspz/delete.do',
                dataType: 'JSON',
                success: function (data) {
                    DGG.loading('close');
                    if (data.code == 0) {
                        DGG.Succeed('操作成功！')
                        setTimeout(function () {
                            layer.closeAll();
                        }, 1000);
                        reloadTable2();
                    } else {
                        DGG.Errors(data.msg);
                    }
                },
                error: function () {
                    DGG.Errors('删除失败，请联系管理员！！');
                }
            })
        }, function () {
        })
    }

    /**
     * 打开编辑流程页面
     */
    function openEditTabPage(id) {
        DGG.loading();
        $.post(sysInfo.basePath + "/zz/zspz/fineedit_production_configuration.html", {id:id}, function (data) {
            dgg.Open({
                title: '编辑证书匹配设置',
                content: data,
                area: '30%',
                btn: ["确定", "取消"],
                yes: function () {
                    matchingEdit()
                }
            });
        }, 'html');

    }
    function matchingEdit(){
        var primaryBusinessForms = $('[name="primaryBusinessForms"]').val();
        var secondBusinessForms = $('[name="secondBusinessForms"]').val();
        var productName  = $('[name="productName"]').val();
        var productNo = $('[name="productNo"]').val();
        var operation = $('[name="operation"]').val();
            if(isEmpty(operation)){
                DGG.Warning('状态不能为空！');
                return;
            }

        var params=$('#editLongCreate').serializeArray();
        <%--params.push({name:'certificateSpecialtys',value:certificateSpecialtys});--%>
        <%--params.push({name:'generalType',value:'${generalType}'});--%>
        DGG.Confire("确定修改证书状态？", '编辑证书状态', function () {
            DGG.loading();
            $.ajax({
                type: 'POST',
                async: true,
                data: params,
                url: sysInfo.basePath + '/zz/zspz/edit.do',
                dataType: 'JSON',
                success: function (data) {
                    DGG.loading('close');
                    if (data.code == 0) {
                        DGG.Succeed('操作成功！')
                        setTimeout(function () {
                            layer.closeAll();
                        }, 1000);
                        reloadTable2();
                    } else {
                        DGG.Errors(data.msg);
                    }
                },
                error: function () {
                    DGG.Errors('保存失败，请联系管理员！！');
                }
            })
        }, function () {
        })
    }

</script>
</body>

</html>